﻿#include "widget.h"
#include "ui_widget.h"
#include <QtCore>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    animation = new QPropertyAnimation(this, "alpha");
    animation->setTargetObject(ui->toolButton);
    animation->setDuration(5000);
    animation->setStartValue(255);
    animation->setEndValue(1);
    animation->setLoopCount(-1); // Infinite loop
    animation->setEasingCurve(QEasingCurve::InOutQuad);

    connect(animation, &QPropertyAnimation::valueChanged, this, &Widget::updateButtonAlpha);

    animation->start();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::updateButtonAlpha(const QVariant &alpha)
{

    qDebug() <<__FUNCTION__<< alpha;
//    QString styleSheet = QString("QToolButton { background-color: rgba(0, 0, 255, %1); }").arg(alpha.toInt());
    QString styleSheet = QString("QToolButton { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, %1), stop:1 rgba(255, 255, 255, %1));}").arg(alpha.toInt());
    ui->toolButton->setStyleSheet(styleSheet);
}

